package org.testis.communicationmodule.services;

import org.testis.communication.client.AtofSnmpClient;
import org.testis.communication.data.CommunicationModuleDataObject;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleService;


/**
 * A class to define an snmp client action for
 * Communication module
 * @author nurhat
 */
public class SnmpClientAction extends AtofModuleAction
{

    /**
     * Function checks whether a given host is available 
     * and supports snmp by using AtofSmtpClient
     * @param request
     * @return
     */
    @Override
    public boolean operateRequest(AtofModuleService request)
    {
        CommunicationModuleDataObject dataObj =
            (CommunicationModuleDataObject) request.getDataObj();
        LogSenderService.putMessageOnQueue(
            "SnmpClientAction",
            AtofLogLevel.INFO,
            "Starting to execute snmp client action ....with data:" + dataObj.
            toString() + "....",
            dataObj.getMessageId());

        boolean result = false;

        AtofSnmpClient snmp = new AtofSnmpClient();

        result = snmp.checkValidation(dataObj.getHost(),
                                      dataObj.getCommandToSend(),
                                      dataObj.getPort());
        AtofLogLevel level = result ? AtofLogLevel.INFO : AtofLogLevel.ERROR;
        LogSenderService.putMessageOnQueue(
            "SnmpClientAction",
            level,
            "SnmpClientAction executed " + (result ? "" : "un") +
            "successfully...",
            dataObj.getMessageId());
        return result;
    }
}